<template>
  <div class="mt20">
    <el-tabs type="border-card">
      <el-tab-pane label="手游">
        <el-card class="box-card mt20" :body-style="{ padding: '18px 0px 5px', boxSizing: 'border-box' }">
          <el-row class="title">
            <el-col :lg="2" class="tac module-title ml20">
              <el-select v-model="queryWyGameInfo.id" @change="searchWyGame" filterable>
                <el-option v-for="item in gameOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-col>
            <el-col :lg="2" class="tac module-title ml20">
              <el-select v-model="queryWyGameInfo.status" @change="searchWyGame" filterable placeholder="请选择游戏状态">
                <el-option v-for="item in stateOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-col>
            <el-col :lg="2" class="tac module-title ml20">
              <el-select v-model="queryWyGameInfo.category_id" @change="searchWyGame" placeholder="请选择游戏类型" filterable>
                <el-option v-for="item in classOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
              </el-select>
            </el-col>
            <el-col :lg="2" class="tac module-title ml20">
              <el-input placeholder="游戏ID" @input="searchWyGame" v-model.trim="queryWyGameInfo.id"></el-input>
            </el-col>
            <el-col :lg="2" class="tac module-title ml20">
              <el-input placeholder="游戏简称" @input="searchWyGame" v-model.trim="queryWyGameInfo.interface_name"></el-input>
            </el-col>
            <el-col :lg="3" class="tal module-title ml20">
              <!-- <el-button plain type="primary">查询</el-button> -->
              <el-button plain type="primary" @click="reset">重置</el-button>
            </el-col>
            <el-col :lg="8" class="tar module-title">
              <el-button plain type="primary" @click="addGame">添加游戏</el-button>
              <el-button plain type="primary" @click="downloadExcel(false)" :loading="downloadLoading1">导出当前页</el-button>
              <el-button plain type="primary" @click="downloadExcel(true)" :loading="downloadLoading2">导出所有页</el-button>
            </el-col>
          </el-row>
          <el-table :data="tableData" :height="tableHeight" v-loading="tableLoading">
            <el-table-column label="序号" width="60" type="index"> </el-table-column>
            <el-table-column prop="name" label="游戏名称" width="120"> </el-table-column>
            <el-table-column prop="interface_name" label="游戏简称"> </el-table-column>
            <el-table-column prop="platform_display" label="游戏平台"> </el-table-column>
            <el-table-column prop="category_display" label="游戏分类"> </el-table-column>
            <el-table-column prop="status_display" label="游戏状态"> </el-table-column>
            <el-table-column prop="server_type_display" label="区服状态"> </el-table-column>
            <el-table-column prop="fcm_flag" label="防沉迷">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.fcm_flag ? '开' : '关' }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="idcrad_flag" label="实名认证">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.idcrad_flag ? '开' : '关' }}
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="priority" sortable label="推荐位"> </el-table-column>
            <el-table-column prop="offical_url" label="官网">
              <template slot-scope="scope">
                <a :href="scope.row.offical_url" target="_blank" style="z-index: 999"> 进入 </a>
              </template>
            </el-table-column>
            <el-table-column prop="enter_game_url" label="游戏入口">
              <template slot-scope="scope">
                <!-- 需要复制的内容,需要指定一个id -->
                <el-button
                  size="mini"
                  round
                  type="success"
                  v-clipboard:copy="scope.row.enter_game_url"
                  v-clipboard:success="onCopy"
                  v-clipboard:error="onError"
                >
                  复制
                </el-button>
                &nbsp;
                <a :href="scope.row.enter_game_url" target="_blank" style="z-index: 999"> 进入 </a>
              </template>
            </el-table-column>
            <el-table-column prop="odpayRate" label="操作">
              <template slot-scope="scope">
                <el-button @click="editGmae(scope.row)">编辑</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            class="tac"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pagination.currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="pagination.perPages"
            layout="sizes, prev, pager, next"
            :total="pagination.total"
          >
          </el-pagination>
        </el-card>
      </el-tab-pane>
      <el-tab-pane label="页游"></el-tab-pane>
    </el-tabs>
    <!-- 添加游戏 -->
    <el-dialog
      :modal-append-to-body="false"
      :top="userAgent ? '60px' : '6vh'"
      :title="editFlag ? '编辑游戏' : '添加游戏'"
      :visible.sync="newGameDialg"
      width="1200px"
      @close="closeDialog"
    >
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="基本信息" name="first">
          <div class="wid-100 pt20 pb20">
            <el-form class="wid-100" inline label-position="right" label-width="120px">
              <el-row>
                <el-col :span="17">
                  <el-col :span="12">
                    <el-form-item label="游戏名称：">
                      <el-input v-model="newGame.name" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="游戏状态：">
                      <el-select v-model="newGame.status" filterable>
                        <el-option v-for="item in stateOptions2" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12" v-if="editFlag">
                    <el-form-item label="游戏ID：">
                      <el-input v-model="newGame.id" disabled></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="区服状态：">
                      <el-select v-model="newGame.server_type" filterable>
                        <el-option v-for="item in serverOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="签订日期：">
                      <el-date-picker v-model="newGame.contract_time" type="date" placeholder="选择日期时间"> </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="游戏简称：">
                      <el-input v-model="newGame.interface_name" placeholder="游戏拼音首字母" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="推荐值：">
                      <el-input v-model="newGame.priority" placeholder="数字越大越靠前" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="游戏平台：">
                      <el-select v-model="newGame.platform" filterable>
                        <el-option v-for="item in gamePlatformOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="游戏人数：">
                      <el-input v-model="newGame.players" placeholder="虚拟人数" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="游戏分类：">
                      <el-select v-model="newGame.category_id" filterable>
                        <el-option v-for="item in classOptions2" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="分成比例：">
                      <el-input v-model="newGame.divide_ratio" placeholder="研发/公司(0 - 1之间的小数)" clearable></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="研发名称：">
                      <el-select v-model="newGame.gcid" filterable>
                        <el-option v-for="item in companyOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="游戏货币：">
                      <el-input v-model="newGame.wing_name" clearable></el-input>
                    </el-form-item>
                  </el-col>
                </el-col>
                <!-- 开关列 -->
                <el-col :span="7">
                  <el-col :span="24">
                    <el-form-item label="防沉迷：">
                      <el-switch v-model="newGame.fcm_flag"> </el-switch>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="实名认证：">
                      <el-switch v-model="newGame.idcrad_flag"> </el-switch>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="充值开关：">
                      <el-switch v-model="newGame.pay_flag"> </el-switch>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="平台支付：">
                      <el-switch v-model="newGame.open_coin"> </el-switch>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="折扣劵开关：">
                      <el-switch v-model="newGame.coupon_flag"> </el-switch>
                    </el-form-item>
                  </el-col>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="游戏简介：">
                    <el-input v-model="newGame.description" style="width: 900px" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="游戏介绍：">
                    <el-input v-model="newGame.description_detail" type="textarea" style="width: 900px" clearable></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-tab-pane>
        <el-tab-pane label="链接配置" name="two">
          <div class="wid-100 pt20 pb20">
            <el-form class="wid-100" inline label-position="right" label-width="120px">
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="游戏官网地址：">
                    <el-input v-model="newGame.offical_url" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="游戏论坛地址：">
                    <el-input v-model="newGame.bbs_url" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="游戏盒子地址：">
                    <el-input v-model="newGame.app_url" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="游戏入口协议：">
                    <el-select v-model="newGame.tcp_type">
                      <el-option v-for="item in tcpTypeOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                    </el-select>
                    <!-- <el-input
                      v-model="newGame.tcp_type"
                      style="width: 800px"
                    ></el-input> -->
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="QQ群：">
                    <el-input v-model="newGame.qq_group" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="QQ群链接：">
                    <el-input v-model="newGame.qq_group_url" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="安卓充值回调：">
                    <el-input v-model="newGame.pay_url" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="IOS充值回调：">
                    <el-input v-model="newGame.pay_url_ios" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="22" :offset="2">
                  <el-form-item label="H5登录地址：">
                    <el-input v-model="newGame.login_url" style="width: 800px"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row v-if="editFlag">
                <el-col :span="22" :offset="2">
                  <el-form-item label="充值密匙：">
                    <el-input v-model="newGame.pay_key" type="textarea" style="width: 800px" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row v-if="editFlag">
                <el-col :span="22" :offset="2">
                  <el-form-item label="登录密匙：">
                    <el-input v-model="newGame.login_key" type="textarea" style="width: 800px" disabled></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-tab-pane>
        <!-- 图片宣传 -->
        <el-tab-pane label="图片宣传" name="three">
          <div class="wid-100 pt20 pb20">
            <el-form class="wid-100" inline label-position="right" label-width="120px">
              <el-row>
                <el-col :span="5" :offset="2">
                  <my-upload
                    :loadImgUrl="newGame.icon ? newGame.icon : ''"
                    :uploadStyle="upload[0]"
                    :keyC="0"
                    :id="upload[0].id"
                    :closeFlag="closeFlag"
                    @imgInfo="getImgInfo(arguments)"
                  ></my-upload>
                  <p>游戏ICON - 100 * 100 px</p>
                </el-col>
                <el-col :span="12">
                  <my-upload
                    :uploadStyle="upload[1]"
                    :keyC="0"
                    :loadImgUrl="newGame.home_recommed_logo ? newGame.home_recommed_logo : ''"
                    :id="upload[1].id"
                    :closeFlag="closeFlag"
                    @imgInfo="getImgInfo(arguments)"
                  ></my-upload>
                  <p>首页游戏推荐宣传图 - 280 * 142 px</p>
                </el-col>
              </el-row>
              <el-row class="mt20">
                <el-col :span="5" :offset="2">
                  <my-upload
                    :uploadStyle="upload[2]"
                    :keyC="0"
                    :loadImgUrl="newGame.channel_recommed_logo ? newGame.channel_recommed_logo : ''"
                    :id="upload[2].id"
                    :closeFlag="closeFlag"
                    @imgInfo="getImgInfo(arguments)"
                  ></my-upload>
                  <p>游戏登录页背景图 - 640 * 1136 px</p>
                </el-col>
                <el-col :span="5" v-for="(item, index) in 5" :key="index">
                  <div :class="item > 3 ? 'mt20' : ''">
                    <my-upload
                      :uploadStyle="upload[3]"
                      :keyC="index"
                      :loadImgUrl="newGame.info_image_list ? newGame.info_image_list[index] : ''"
                      :id="upload[0].id + '-' + index"
                      :closeFlag="closeFlag"
                      @imgInfo="getImgInfo(arguments)"
                    ></my-upload>
                    <p>游戏五宣图{{ item }} - 1080 * 920 px</p>
                  </div>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-tab-pane>
      </el-tabs>

      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="passCancel">取 消</el-button>
        <el-button type="primary" @click="passConfirm" size="small" :loading="btnLoading">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import upload from '@/components/upload/upload.vue';
// 复制
export default {
  data() {
    return {
      flag: false,
      btnLoading: false,
      tableLoading: false,
      editFlag: false, // 编辑/添加
      downloadLoading1: false,
      downloadLoading2: false,
      gameOptions: [{ value: '', label: '全部游戏(all)' }], // 全部游戏
      stateOptions: [{ value: '', label: '所有状态' }], // 所有游戏状态
      stateOptions2: [], // 所有游戏状态(去掉所有状态)
      classOptions: [{ value: '', label: '所有类型' }], // 所有游戏类型
      classOptions2: [], // 所有游戏类型(去掉所有类型)
      serverOptions: [], // 区服状态
      gamePlatformOptions: [], // 游戏平台
      companyOptions: [], // 研发公司列表
      tcpTypeOptions: [], // 入口协议
      tableData: [], // 数据
      newGameDialg: false, // 展示
      // dialog
      activeName: 'first',
      // 分页
      pagination: {
        total: 0, // 表格数据条数
        pages: 0, // 总页数
        perPages: 10, // 每页的数量
        currentPage: 1, // 当前页
      },
      // 查询
      queryWyGameInfo: {
        id: '', // ID
        interface_name: '', // 游戏简称
        status: '', //游戏状态
        category_id: '', // 游戏类型
        page: 1, // 第一页默认第一(非必填)
        per_page: 10, // 每页数量默认10(非必填)
      },
      // 新建 添加游戏字段
      newGame: {
        // 第一页
        name: '', // 游戏名
        status: '', // 游戏状态
        fcm_flag: true, // 游戏状态开关
        id: '', // 游戏ID
        server_type: '', // 区服状态
        idcrad_flag: true, // 实名认证开关
        interface_name: '', // 游戏简称
        priority: '', // 推荐值
        pay_flag: true, // 充值开关
        platform: '', // 游戏平台
        players: 0, // 游戏人数
        open_coin: true, // 平台支付
        category_id: '', // 游戏分类
        divide_ratio: '', // 游戏分成比例
        coupon_flag: true, // 优惠卷开关
        gcid: '', // 游戏商id（研发名称） 与研发列表相关联
        wing_name: '', // 游戏货币名称
        description: '', // 游戏简介
        description_detail: '', // 游戏介绍
        contract_time: new Date().toLocaleString().substr(0, 10), // 签订日期
        // 第二页 链接配置
        offical_url: '', // 游戏官网地址
        bbs_url: '', // 游戏论坛地址
        app_url: '', // 游戏盒子地址
        tcp_type: '', // 游戏入口协议
        qq_group: '', // QQ群
        qq_group_url: '', // QQ群链接
        pay_url: '', // 安卓充值回调 / H5充值回调 合并为一个
        pay_url_ios: '', // IOS充值回调
        login_url: '', // H5登录地址
        pay_key: '', // 充值密匙
        login_key: '', // 登录密匙
        // 第三页 上传图片
        icon: '', // 游戏ICON
        home_recommed_logo: '', // 首页游戏推荐宣传图
        channel_recommed_logo: '', // 游戏登录页背景图
        info_image_list: ['', '', '', '', ''], // 游戏五宣图
      },
      editGmaeInfo: {},
      closeFlag: false, // 编辑框关闭
      // 上传
      upload: [
        { class: 'gameIcon', index: 0, id: 'gameIcon' },
        { class: 'indexPublicity', index: 1, id: 'indexPublicity' },
        { class: 'loginBackground', index: 2, id: 'loginBackground' },
        { class: 'gameFivePublicity', index: 3, id: 'gameFivePublicity' },
      ],
      // 分类
      total_category: [],
      isShow: false,
      word: 'success',
    };
  },
  computed: {},
  created() {
    this.getWyGameState();
    this.getWyGameList();
    this.getCurrentScreen();
  },
  mounted() {},
  methods: {
    // 查询
    searchWyGame() {
      this.queryWyGameInfo.page = 1;
      this.getWyGameState(this.queryWyGameInfo);
    },
    // 每页数量变化
    handleSizeChange(val) {
      this.queryWyGameInfo.per_page = val;
      this.getWyGameState(this.queryWyGameInfo);
    },
    // 当前页
    handleCurrentChange(val) {
      this.queryWyGameInfo.page = val;
      this.getWyGameState(this.queryWyGameInfo);
    },
    // 获取游戏列表信息
    getWyGameState(params) {
      return new Promise(resolve => {
        this.tableLoading = true;
        let queryObj = params || this.queryWyGameInfo;
        this.$api.getWyGameState(queryObj).then(res => {
          this.tableLoading = false;
          if (res.code == 0 || res.code == 200) {
            this.tableData = res.items;
            this.pagination.currentPage = res.page;
            this.pagination.pages = res.pages;
            this.pagination.total = res.total;
            this.pagination.perPages = res.per_page;
            resolve(res.items);
          }
        });
      });
    },
    // 获取游戏列表下拉框信息
    getWyGameList() {
      // 1、获取游戏名+ 简称
      this.$api.getWyGameSelectList().then(res => {
        if (res.code == 0 || res.code == 200) {
          let list = res.data.map((item, index) => {
            return {
              value: item.id,
              label: `${item.name} - ${item.interface_name}`,
            };
          });
          this.gameOptions = [...this.gameOptions, ...list];
        }
      });
      // 2、获取游戏状态、游戏类型等下拉框选项
      this.getSelectList('game_status', 'stateOptions', 0);
      this.getSelectList('game_category', 'classOptions', 1);
      this.getSelectList('game_server_type', 'serverOptions', 2);
      this.getSelectList('game_platform', 'gamePlatformOptions', 3);
      this.getSelectList('tcp_type', 'tcpTypeOptions', 4);

      // 3、 获取研发公司列表
      this.$api.getCompanyList({ per_page: 9999 }).then(res => {
        if (res.code == 0 || res.code == 200) {
          this.companyOptions = res.items.map(item => {
            return { value: Number(item.id), label: item.name };
          });
        }
      });
    },
    /* 
      函数getSelectList：批量查询下拉框值；
     
     keyP: 表示查询的参数值；
        key 可取以下值
        hannel_clearing_type:渠道合作方式 | game_status:游戏状态 
        game_server_type:区服状态 | game_platform:游戏平台 | game_category:游戏分类
        tcp_type:入口协议

      targetP: 表示目标存储位置；
      num: 表示暂存在 total_category 中的位置；
    */
    getSelectList(keyP, targetP, num) {
      this.$api.wyChoices({ key: keyP }).then(res => {
        if (res.code == 0 || res.code == 200) {
          if (num == 4) {
            this.total_category[num] = res.data.map((item, index) => {
              return { value: item.id, label: item.name };
            });
          } else {
            this.total_category[num] = res.data.map((item, index) => {
              return { value: Number(item.id), label: item.name };
            });
          }
          // 游戏分类
          if (num === 1) {
            this.classOptions2 = [...this.total_category[num]];
          }
          // 游戏状态
          if (num === 0) {
            this.stateOptions2 = [...this.total_category[num]];
          }
          this[targetP] = [...this[targetP], ...this.total_category[num]];
        }
      });
    },
    // 更新getImgInfo
    getImgInfo(data) {
      switch (data[2] && data[2].index) {
        case 0:
          this.newGame.icon = data[0];
          break;
        case 1:
          this.newGame.home_recommed_logo = data[0];
          break;
        case 2:
          this.newGame.channel_recommed_logo = data[0];
          break;
        case 3:
          this.newGame.info_image_list[data[1]] = data[0];
          break;
      }
    },
    // 新建 / 编辑 通过
    passConfirm() {
      // 1、检查该输入的都输入了没
      if (this.checkInputInfo()) return;
      this.btnLoading = true;
      if (!this.editFlag) {
        // 新建
        this.$api.newWyGame(this.newGame).then(res => {
          this.btnLoading = false;
          if (res.code == 0 || res.code == 200) {
            this.$message.success('新建游戏成功！');
            this.newGameDialg = false;
            this.closeFlag = true;
            this.$store.commit('changeDialogFlag', true);
          }
        });
      } else {
        // 编辑
        // this.initNewGame();
        this.$api.editWyGame(this.newGame).then(res => {
          this.btnLoading = false;
          if (res.code == 0 || res.code == 200) {
            this.$message.success('编辑成功！');
            this.getWyGameState();
            this.newGameDialg = false;
            this.$store.commit('changeDialogFlag', true);
          }
        });
      }
    },
    passCancel() {
      this.newGameDialg = false;
      // if (this.editFlag) {
      //   this.initNewGame();
      // }
    },
    // 检查输入的内容有没有完整
    checkInputInfo() {
      if (!this.newGame.name) {
        this.$message.warning('请输入游戏名称');
        return true;
      }
      if (this.newGame.status === '' || this.newGame.status === undefined) {
        this.$message.warning('请选择游戏状态');
        return true;
      }
      if (this.newGame.server_type === '' || this.newGame.server_type === undefined) {
        this.$message.warning('请选择区服状态');
        return true;
      }
      if (!this.newGame.priority) {
        this.$message.warning('请输入推荐值');
        return true;
      }
      if (this.newGame.platform === '' || this.newGame.platform === undefined) {
        this.$message.warning('请选择游戏平台');
        return true;
      }
      if (!this.newGame.category_id) {
        this.$message.warning('请输入游戏分类');
        return true;
      }
      if (!this.newGame.divide_ratio) {
        this.$message.warning('请输入分成比例');
        return true;
      }
      if (this.newGame.gcid === '' || this.newGame.gcid === undefined) {
        this.$message.warning('请选择研发名称');
        return true;
      }
      if (!this.newGame.wing_name) {
        this.$message.warning('请输入游戏货币');
        return true;
      }
      if (!this.newGame.offical_url) {
        this.$message.warning('请输入游戏官网地址');
        return true;
      }
      if (!this.newGame.bbs_url) {
        this.$message.warning('请输入游戏论坛地址');
        return true;
      }
      return false;
    },
    handleClick(tab, event) {},
    // 编辑游戏
    editGmae(r) {
      this.editFlag = true;
      this.newGameDialg = true;
      this.newGame = r;
      this.$store.commit('changeDialogFlag', false);
    },
    // 添加游戏
    addGame() {
      this.editFlag = false;
      this.newGameDialg = true;
      this.$store.commit('changeDialogFlag', false);
    },
    // 重置
    reset() {
      this.queryWyGameInfo.id = '';
      this.queryWyGameInfo.interface_name = '';
      this.queryWyGameInfo.status = '';
      this.queryWyGameInfo.category_id = '';
      this.queryWyGameInfo.page = 1;
      this.queryWyGameInfo.per_page = 10;
      this.pagination.currentPage = 1;
      this.pagination.perPages = 10;
      this.getWyGameState(this.queryWyGameInfo);
    },
    initNewGame() {
      this.newGame = {
        // 第一页
        name: '', // 游戏名
        status: '', // 游戏状态
        fcm_flag: true, // 游戏状态开关
        id: '', // 游戏ID
        server_type: '', // 区服状态
        idcrad_flag: true, // 实名认证开关
        interface_name: '', // 游戏简称
        priority: '', // 推荐值
        pay_flag: true, // 充值开关
        platform: '', // 游戏平台
        players: 0, // 游戏人数
        open_coin: true, // 平台支付
        category_id: '', // 游戏分类
        divide_ratio: '', // 游戏分成比例
        coupon_flag: true, // 优惠卷开关
        gcid: '', // 游戏商id（研发名称） 与研发列表相关联
        wing_name: '', // 游戏货币名称
        description: '', // 游戏简介
        description_detail: '', // 游戏介绍
        contract_time: new Date().toLocaleString().substr(0, 10), // 签订日期
        // 第二页 链接配置
        offical_url: '', // 游戏官网地址
        bbs_url: '', // 游戏论坛地址
        app_url: '', // 游戏盒子地址
        tcp_type: '', // 游戏入口协议
        qq_group: '', // QQ群
        qq_group_url: '', // QQ群链接
        pay_url: '', // 安卓充值回调 / H5充值回调 合并为一个
        pay_url_ios: '', // IOS充值回调
        login_url: '', // H5登录地址
        pay_key: '', // 充值密匙
        login_key: '', // 登录密匙
        // 第三页 上传图片
        icon: '', // 游戏ICON
        home_recommed_logo: '', // 首页游戏推荐宣传图
        channel_recommed_logo: '', // 游戏登录页背景图
        info_image_list: ['', '', '', '', ''], // 游戏五宣图
      };
    },
    // 复制链接方法
    onCopy(e) {
      this.$message.success('复制成功');
    },
    onError(e) {
      this.$message.warning('该浏览器不支持自动复制');
    },
    closeDialog() {
      if (this.editFlag) {
        this.initNewGame();
        this.getWyGameState();
      }
      this.$store.commit('changeDialogFlag', true);
    },
    // 下载excel
    async downloadExcel(flage) {
      let excel = '<table>';
      //设置表头
      let list;
      if (!flage) {
        // 当前页
        this.downloadLoading1 = true;
        list = this.tableData;
      } else {
        // 所有页
        this.downloadLoading2 = true;
        this.queryWyGameInfo.page = 1;
        this.queryWyGameInfo.per_page = 9999;
        list = await this.getWyGameState(this.queryWyGameInfo);
      }
      let row =
        '<tr>' +
        '<td>序号</td>' +
        '<td>游戏名称</td>' +
        '<td>游戏简称</td>' +
        '<td>游戏平台</td>' +
        '<td>游戏分类</td>' +
        '<td>游戏状态</td>' +
        '<td>区服状态</td>' +
        '<td>防成谜</td>' +
        '<td>实名认证</td>' +
        '<td>推荐位</td>' +
        '<td>官网</td>' +
        '<td>游戏入口</td>' +
        '</tr>';
      //换行
      excel += row;
      let l = list.map((o, i) => {
        return `<tr><td>${i + 1}</td><td>${o.name}</td><td>${o.interface_name}</td><td>${o.platform_display}</td><td>${o.category_display}</td><td>${
          o.status_platform_display
        }</td><td>${o.actives}</td>
        <td>${o.fcm_flag ? '开' : '关'}</td><td>${o.idcrad_flag ? '开' : '关'}</td><td>${o.priority}</td><td>${o.offical_url}</td><td>${o.enter_game_url}</td>
        </tr>`;
      });

      excel += l.join('');
      excel += '</table>';
      //利用时间起文件名称
      var date = new Date();
      var fileName = '游戏列表' + date.getFullYear() + (date.getMonth() + 1) + date.getDate() + '号' + date.getHours() + '点' + date.getMinutes() + '分';
      this.tableToExcel(excel, fileName);
      this.downloadLoading1 = false;
      this.downloadLoading2 = false;
      this.reset();
    },
  },
  components: {
    'my-upload': upload,
  },
};
</script>
<style lang='stylus' scoped>
body {
}

.el-dialog__body {
  padding: 10px 20px 30px !important;
}
</style>
